<?php
/*
 * emarket - a website to create your own online-shop.  
 * Copyright (C) 2009  Frédéric Delorme
 *
 * This file is part of emarket.
 *
 * emarket is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * emarket is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with emarket.  If not, see <http://www.gnu.org/licenses/>.
 *
 * To contact me: frederic.delorme@gmail.com
 * to see some information on te project : http://code.google.col/p/os-emarket/
 *
 */
require_once("webapp/application/application.php");
require_once("framework/paginator.php");
/**
 * Management of the user session, including: login, logout, register and cart edition.
 * @author frederic
 */
class ProfileManager extends Application{
	/**
	 * login an existing user.
	 * @return unknown_type
	 */
	public function login(){
		return "profile/login";
	}
	/**
	 * login an existing user.
	 * @return unknown_type
	 */
	public function verifyAuthorization(){
		
				// load categories list
		$this->products=__query_entities(
				"product",
					$where = "",
					$order = $order = array(	array('field'=>"availableat_date",'comparator'=>"ASC")),
					$limit = array("max"=>6)
				);
		$this->addEntity('product',$this->products);
		__template_set('products',self::$_entities['product']);
		// Cart management
		$this->cart = CartHelpers::get();
		__template_set("cart",$this->cart);
		
		
		return "home/main";
	}
	/**
	 * Try to register a new user into User database.
	 * @return unknown_type
	 */
	public function create(){
		$user = $_POST;
		__template_set("user",$user);
		return "profile/create";
	}
	
	/**
	 * Disply the regsiter formular.
	 * @return template to be displayed
	 */
	public function register(){
		return "profile/register";
	}
	
	/**
	 * Logout current user.
	 * @return unknown_type
	 */
	public function logout(){
		return "profile/logout";
	}
	/**
	 * (non-PHPdoc)
	 * @see framework/WebApp#render()
	 */	
	public function render($action){
		if($action==""){
			return "profile/main";
		}else{
			return "profile/$action";
		}
	}
}
?>